package xyz.yuzegod.megawalls.classes.normal.shaman;

import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.Skill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;
import xyz.yuzegod.megawalls.util.ParticleEffect;
import xyz.yuzegod.megawalls.util.PlayerUtils;

import java.util.ArrayList;
import java.util.List;

public class MainSkill extends Skill
{
    public MainSkill(final Classes classes) {
        super("龙卷风", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 5;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 1.0;
            }
            case 2: {
                return 1.12;
            }
            case 3: {
                return 1.25;
            }
            case 4: {
                return 1.38;
            }
            case 5: {
                return 7.5;
            }
            default: {
                return 1.0;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        lore.add(" §8▪ §7生成一个毁灭性的龙卷风,");
        lore.add("   §7每秒对沿途玩家造成§a" + this.getAttribute(level) + "§7点伤害。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkillLevel();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkillLevel();
    }
    
    @Override
    public boolean use(final GamePlayer gamePlayer, final KitStatsContainer kitStats) {
        final int level = kitStats.getSkillLevel();
        final Player player = gamePlayer.getPlayer();
        new BukkitRunnable() {
            int seconds = 0;
            
            public void run() {
                if (this.seconds == 5 || !gamePlayer.isOnline()) {
                    gamePlayer.setEnergy(0);
                    this.cancel();
                    return;
                }
                for (final Player other : PlayerUtils.getNearbyPlayers((Entity)player, 5.0)) {
                    final GamePlayer gameOther = GamePlayer.get(other.getUniqueId());
                    if (!gameOther.isSpectator()) {
                        if (GamePlayer.get(player.getUniqueId()).getGameTeam().isInTeam(gameOther)) {
                            continue;
                        }
                        other.damage(MainSkill.this.getAttribute(level), (Entity)player);
                        ParticleEffect.SMOKE_NORMAL.display(0.0f, 0.0f, 0.0f, 1.0f, 5, other.getLocation(), 10.0);
                    }
                }
                ++this.seconds;
            }
        }.runTaskTimer((Plugin)MegaWalls.getInstance(), 0L, 20L);
        return true;
    }
}
